package cn.mxb.logic.action.mxb;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

import cn.mxb.floor.pagination.Result;
import cn.mxb.floor.web.BaseAction;
import cn.mxb.logic.entity.SysCount;
import cn.mxb.logic.entity.SysTown;
import cn.mxb.logic.entity.SysVillage;
import cn.mxb.logic.entity.SysZu;
import cn.mxb.logic.entity.MxbPolicy;
import cn.mxb.logic.service.ISysCountService;
import cn.mxb.logic.service.ISysTownService;
import cn.mxb.logic.service.ISysVillageService;
import cn.mxb.logic.service.ISysZuService;
import unit.IdGenerator;
import cn.mxb.logic.service.IMxbPolicyService;

@SuppressWarnings({ "serial", "rawtypes" })
public class MxbPolicyAction extends BaseAction implements Preparable,ModelDriven {
	protected static final String List_JSP = "/WEB-INF/page/web/mxb/mxbPolicyList.jsp";
	protected static final String ADD_JSP = "/WEB-INF/page/web/mxb/mxbPolicyAdd.jsp";
	protected static final String UPDATE_JSP = "/WEB-INF/page/web/mxb/mxbPolicyUpdate.jsp";
	protected static final String Listzc_JSP = "/WEB-INF/page/web/mxb/mxbPolicyzcList.jsp";
	protected static final String ADDzc_JSP = "/WEB-INF/page/web/mxb/mxbPolicyzcAdd.jsp";
	protected static final String UPDATEzc_JSP = "/WEB-INF/page/web/mxb/mxbPolicyzcUpdate.jsp";
	
	private MxbPolicy mxbPolicy;
	@Autowired
	private IMxbPolicyService mxbPolicyService;
	@Autowired
	private ISysCountService sysCountService;
	@Autowired
	private ISysTownService sysTownService;
	@Autowired
	private ISysVillageService sysVillageService;
	@Autowired
	private ISysZuService sysZuService;
	
	private Result<MxbPolicy> pageResult;
	
	private List<MxbPolicy> mxbPolicyAllList; 
	private List<SysCount> sysCountAllList; 
	private List<SysTown> sysTownAllList; 
	private List<SysVillage> sysVillageAllList; 
	private List<SysZu> sysZuAllList; 
	
	private Map<Integer,String> countNameMap = new HashMap<Integer, String>();    //县名
	private Map<Integer,String> townNameMap = new HashMap<Integer, String>();     //镇名
	private Map<Integer,String> villageNameMap = new HashMap<Integer, String>();  //村名
	private Map<Integer,String> zUidMap = new HashMap<Integer, String>(); 
	
	private String familyNameY; //参合家庭姓名搜索关键字
	
	/**
	 * @file_name: 跳转mxb添加界面
	 */
	public String openAdd(){
		setForwardView(ADD_JSP);
		return SUCCESS;
	}
	/**
	 * @file_name: 跳转zc添加界面
	 */
	public String openzcAdd(){
		setForwardView(ADDzc_JSP);
		return SUCCESS;
	}
	/**
	 * 慢性病添加
	 * @throws Exception 
	 * @return_type: String
	 */
	public String add() throws Exception{
		System.out.println("add");
		IdGenerator id = new IdGenerator(1023);
		System.out.println("id="+(id.getNextId()).intValue());
		mxbPolicy.setMxbId((id.getNextId()).intValue()+"");
		mxbPolicyService.add(mxbPolicy);
		return openList();		
	}
	/**
	 * 慢性病zc添加
	 * @throws Exception 
	 * @return_type: String
	 */
	public String zcadd() throws Exception{
		System.out.println("add");
		IdGenerator id = new IdGenerator(1023);
		System.out.println("id="+(id.getNextId()).intValue());
		mxbPolicy.setPolicyId((id.getNextId()).intValue()+"");
		mxbPolicyService.add(mxbPolicy);
		return openList();		
	}
	
	/**
	 * @file_name 打开列表
	 * @return 
	 */
	public String openList(){
		try{
			pageResult = mxbPolicyService.find(mxbPolicy, getPage(), getRow());
			for(MxbPolicy mxbPolicy : pageResult.getData()){
				/*if(null != mxbPolicy.getCountId()  && !"".equals(mxbPolicy.getCountId())){
					countNameMap.put(mxbPolicy.getCountId(),sysCountService.findByProperty("countId", mxbPolicy.getCountId()+"").getCountName());
				}
				if(null != mxbPolicy.getTownId() && !"".equals(mxbPolicy.getTownId())){
					townNameMap.put(mxbPolicy.getTownId(),sysTownService.findByProperty("sysTownId", mxbPolicy.getTownId()+"").getSysTownName());
				}
				if(null != mxbPolicy.getVillageId() && !"".equals(mxbPolicy.getVillageId())){
					villageNameMap.put(mxbPolicy.getVillageId(),sysVillageService.findByProperty("villageId", mxbPolicy.getVillageId()+"").getVillageName());
				}
				if(null != mxbPolicy.getZuId() && !"".equals(mxbPolicy.getZuId())){
					zUidMap.put(mxbPolicy.getZuId(),sysZuService.findByProperty("villageId", mxbPolicy.getZuId()+"").getZuId()+"");
				}*/
				if(null != mxbPolicy.getMxbId()  && !"".equals(mxbPolicy.getMxbId())){
					setForwardView(List_JSP);
				}
				if(null != mxbPolicy.getPolicyId()  && !"".equals(mxbPolicy.getPolicyId())){
					setForwardView(Listzc_JSP);
				}
			}
			return SUCCESS;
		}catch(Exception e){
			System.out.println(e);
		}
		return SUCCESS;
	}
	
	/**
	 * @file_name:慢性病删除 
	 */
	public String delete(){
		mxbPolicyService.delete(mxbPolicy.getId());
		mxbPolicy.setMxbId("1");
		return openList();
	}
	
	/**
	 * @return_type: 
	 * @file_name:  打开修改页面
	 */
	public String openUpdate(){
		mxbPolicy =  mxbPolicyService.findByProperty("id",mxbPolicy.getId()+"");
		sysCountAllList = sysCountService.findAllList();
		sysTownAllList = sysTownService.findAllList();
		sysVillageAllList = sysVillageService.findAllList();
		setForwardView(UPDATE_JSP);
		return SUCCESS;
	}
	
	/**
	 * 修改慢性病 
	 * @return_type: 
	 */
	public String update(){
		mxbPolicyService.add(mxbPolicy);
		mxbPolicy = null;
		mxbPolicy.setMxbId("1");
		return openList();
	}
	
	
	@Override
	public Object getModel() {
		return mxbPolicy;
	}
	@Override
	public void prepare() throws Exception {
		if(mxbPolicy ==null){
			mxbPolicy = new MxbPolicy();
		}
	}


	public MxbPolicy getMxbPolicy() {
		return mxbPolicy;
	}

	public void setMxbPolicy(MxbPolicy mxbPolicy) {
		this.mxbPolicy = mxbPolicy;
	}

	public Result<MxbPolicy> getPageResult() {
		return pageResult;
	}

	public void setPageResult(Result<MxbPolicy> pageResult) {
		this.pageResult = pageResult;
	}
	
	public List<SysCount> getSysCountAllList() {
		return sysCountAllList;
	}

	public void setSysCountAllList(List<SysCount> sysCountAllList) {
		this.sysCountAllList = sysCountAllList;
	}

	public List<SysTown> getSysTownAllList() {
		return sysTownAllList;
	}

	public void setSysTownAllList(List<SysTown> sysTownAllList) {
		this.sysTownAllList = sysTownAllList;
	}

	public Map<Integer, String> getCountNameMap() {
		return countNameMap;
	}

	public void setCountNameMap(Map<Integer, String> countNameMap) {
		this.countNameMap = countNameMap;
	}

	public Map<Integer, String> getTownNameMap() {
		return townNameMap;
	}

	public void setTownNameMap(Map<Integer, String> townNameMap) {
		this.townNameMap = townNameMap;
	}

	public Map<Integer, String> getVillageNameMap() {
		return villageNameMap;
	}

	public void setVillageNameMap(Map<Integer, String> villageNameMap) {
		this.villageNameMap = villageNameMap;
	}

	public List<SysVillage> getSysVillageAllList() {
		return sysVillageAllList;
	}

	public void setSysVillageAllList(List<SysVillage> sysVillageAllList) {
		this.sysVillageAllList = sysVillageAllList;
	}

	public List<MxbPolicy> getMxbPolicyAllList() {
		return mxbPolicyAllList;
	}

	public void setMxbPolicyAllList(List<MxbPolicy> mxbPolicyAllList) {
		this.mxbPolicyAllList = mxbPolicyAllList;
	}

	public List<SysZu> getSysZuAllList() {
		return sysZuAllList;
	}

	public void setSysZuAllList(List<SysZu> sysZuAllList) {
		this.sysZuAllList = sysZuAllList;
	}

	public Map<Integer, String> getzUidMap() {
		return zUidMap;
	}

	public void setzUidMap(Map<Integer, String> zUidMap) {
		this.zUidMap = zUidMap;
	}

	public String getFamilyNameY() {
		return familyNameY;
	}

	public void setFamilyNameY(String familyNameY) {
		this.familyNameY = familyNameY;
	}

	


	

	
	
}
